package filters;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

@WebFilter("*.action")
public class CharacterEncodingFilter implements Filter {


    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        //请求过来时，拦截，设置编码
        request.setCharacterEncoding("UTF-8");
        //放行
        chain.doFilter(request,response);
        //下面的代码是响应回来时拦截
        response.setCharacterEncoding("utf-8");
        //OutOfMemoryError

    }

    @Override
    public void destroy() {

    }
}
